<?php

namespace App\Http\Middleware;

use App\Models\Rbac\GuardUser;
use Closure;
use Illuminate\Support\Facades\Session;

class Guard
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next) {

        if(!$request->hasHeader('from')){
            return responseFail(100006);
        }
        if(!$request->hasHeader('token')){
            return responseFail(100004);
        }
        $id = checkJWT($request->header('token'))['id'];
        $guardUser = (new GuardUser())->getRecordById($id);
        if(empty($guardUser))return responseFail(100002);


        $response = $next($request);
        /*$response->header('Access-Control-Allow-Origin', '*');
        $response->header('Access-Control-Allow-Headers', 'Origin, Content-Type, Cookie, Accept');
        $response->header('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, OPTIONS');
        $response->header('Access-Control-Allow-Credentials', 'false');*/
        return $response;





    }
}
